// pages/detail/detail.js
const app = getApp();
var that;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        course: {},
        commentList: [],
        root: app.rootUrl
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        that = this;
        var courseid = options.courseid;
        wx.request({
            url: app.rootUrl + '/getCourse',
            data: {
                'courseId': courseid
            },
            header: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'POST',
            success: function (res) {
                that.setData({
                    course: res.data
                });
            }
        })
    },
    addApply: function (e) {
        var index = e.currentTarget.dataset.index;
        var that = this;
        if (app.accountInfo() == null) {
            wx.showToast({
                title: '请登录',
                icon: 'none',
            })
        }
        let accountType = app.accountInfo().accountType;
        if (accountType*1 == 1) {
            wx.showToast({
                title: '只有学生可以申请',
                icon: 'none',
            })
            return false
        }
        wx.request({
            url: app.rootUrl + '/saveApply',
            data: {
                'userId': app.accountInfo().accountId,
                'courseId': index
            },
            header: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'POST',
            success: function (res) {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                })
            }
        })
    },
})